<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>文本框之清除图标 - jQuery EasyUI 演示</title>
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../demo.css">
	<script type="text/javascript" src="../../jquery.min.js"></script>
	<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
	<h2 title="TextBox with Clear Icon">文本框之清除图标</h2>
	<p title="This example shows how to create an textbox with an icon to clear the input element itself.">　　本例展示如何创建一个带有图标（可用来自行清除其所输的元素，如无则不出现）的文本框。</p>
	<div style="margin:20px 0 20px 0;"></div>
	<div class="easyui-panel" style="width:100%;max-width:400px;padding:20px 20px;">
		<div>
			<input id="tt" style="width:100%;" data-options="
					label: '邮箱：', labelPosition: 'left', labelWidth:50, labelAlign:'right',
					prompt: '请在此输入所需值！', value: 'my@email.com',
					icons:[{
						iconCls:'icon-search',
						handler: function(e){
							var v = $(e.data.target).textbox('getValue');
							alert(v ? ('你刚才输入的值为： '+v) : '无任何输入！');
						}
					}]
					">
		</div>
	</div>
	<script>
		$.extend($.fn.textbox.methods, {
			addClearBtn: function(jq, iconCls){
				return jq.each(function(){
					var t = $(this);
					var opts = t.textbox('options');
					opts.icons = opts.icons || [];
					opts.icons.unshift({
						iconCls: iconCls,
						handler: function(e){
							$(e.data.target).textbox('clear').textbox('textbox').focus();
							$(this).css('visibility','hidden');
						}
					});
					t.textbox();
					if (!t.textbox('getText')){
						t.textbox('getIcon',0).css('visibility','hidden');
					}
					t.textbox('textbox').bind('keyup', function(){
						var icon = t.textbox('getIcon',0);
						if ($(this).val()){
							icon.css('visibility','visible');
						} else {
							icon.css('visibility','hidden');
						}
					});
				});
			}
		});
		
		$(function(){
			$('#tt').textbox().textbox('addClearBtn', 'icon-clear');
		});
	</script>
</body>
</html>